/* 1. 引入 axios */
import axios from "axios"
/* const instance = axios.create({
    baseURL: 'https://api-hmugo-web.itheima.net/api/public/v1/',
}); */
axios.defaults.baseURL = "https://api-hmugo-web.itheima.net/api/public/v1/"
axios.defaults.headers.common['Authorization'] = sessionStorage.getItem('token')
//
// 添加拦截器
// 请求和响应的拦截器
// Add a request interceptor
axios.interceptors.request.use(function (config) {
    // Do something before request is sent
    // Todo 将 auth_token 将它加到请求数据中
    
    return config;
  }, function (error) {
    // Do something with request error
    return Promise.reject(error);
  });

// Add a response interceptor
axios.interceptors.response.use(function (response) {
    // Any status code that lie within the range of 2xx cause this function to trigger
    // Do something with response data
    return response.data;
  }, function (error) {
    // Any status codes that falls outside the range of 2xx cause this function to trigger
    // Do something with response error
    return Promise.reject(error);
  });

export default axios;